package com.briup.corejava.day19;

import java.io.*;

/**
 * 使用数据流和文件流写出Java中的基本数据类型和字符串
 */
public class Test3_dw {
    public static void main(String[] args) {
        FileOutputStream fos = null;
        DataOutputStream dos = null;
        File file = new File("src/com/briup/corejava/day19/file/b.txt");

        try {
            fos = new FileOutputStream(file);
            dos = new DataOutputStream(fos);
            // 写出数据
            dos.writeInt(10);
            dos.writeLong(20L);
            dos.writeDouble(30.02);
            dos.writeFloat(20.09f);
            dos.writeBoolean(true);
            dos.writeChar('a');
            dos.writeUTF("中国");

            dos.flush();
            System.out.println("数据写出成功！");

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            if(dos!=null) {
                try {
                    dos.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if(fos!=null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
